home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- ////////////////////////////////////////////////////////////////////////////////
- //
- // Procedure Name:
- // MLdeleteUnused
- //
- // Description:
- // Delete unused multi-lister (render) nodes
- //
- // Input Arguments:
- // None.
- //
- // Return Value:
- // None.
- //
- global proc MLdeleteUnused() {
- int $i, $j, $count;
-
- // Delete all empty shadinggroups or not connected shadinggroups first.
- string $sets[] = `ls -sets`;
- string $objs[];
- $count = `size($sets)`;
- for ($i = 0; $i < $count; $i++) {
- if (`sets -q -renderable $sets[$i]`) {
- if ($sets[$i] != "initialShadingGroup" &&
- $sets[$i] != "initialParticleSE") {
- $objs = `sets -q $sets[$i]`;
- if (size($objs) == 0) {
- deleteIfNotReferenced $sets[$i];
- } else {
- string $connSurf[] =
- `listConnections ($sets[$i] + ".surfaceShader")`;
- string $connVol[] =
- `listConnections ($sets[$i] + ".volumeShader")`;
- string $connDisp[] =
- `listConnections ($sets[$i] + ".displacementShader")`;
- if (`size $connSurf` == 0 && `size $connVol` == 0 &&
- `size $connDisp` == 0) {
- deleteIfNotReferenced $sets[$i];
- }
- }
- }
- }
- clear $objs;
- }
-
- // Delete all unconnected materials.
- int $shouldDelete = false;
- int $count2;
- string $materials[] = `ls -long -mat`;
- string $se[];
- string $conn[];
- $count = `size($materials)`;
- for ($i = 0; $i < $count; $i++) {
- // Now determine if the readOnly connections are done.
- string $currShader = $materials[$i];
-
- $conn = `listConnections -shapes true -connections true -source false $currShader`;
- // conn is an array of plug/connection pairs
- $count2 = `size($conn)`;
- for ($j = 0; $j < $count2; $j+=2) {
- clear $se;
- if ($conn[$j] != ($currShader + ".message")) {
- $shouldDelete = false;
- break;
- } else {
- // must explicitly check for a shading engine connection on message
- $se = `listConnections -type shadingEngine ($conn[$j])`;
- if (size($se) != 0) {
- $shouldDelete = false;
- break;
- } else {
- $shouldDelete = true;
- }
- }
- }
-
- if ($shouldDelete) {
- deleteIfNotReferenced $currShader;
- }
-
- $shouldDelete = false;
- clear $conn;
- clear $se;
- }
-
- // Iterate multi-times and delete textures + utility nodes.
- int $deleteAnything = true;
- int $oldSizeAll = 0;
- string $all[];
- string $class[];
- string $conn[];
- string $base[];
- string $type,$node,$connType,$attrName;
- while ($deleteAnything) {
- $deleteAnything = false;
- $all = `ls -long -dep`;
- $count = size($all);
- if($oldSizeAll != $count) {
- for ($node in $all) {
- // Deleting one node can delete other connected nodes.
- if (!`objExists $node`)
- continue;
-
- $type = `nodeType $node`;
- $class = `getClassification $type`;
-
- if (size($class) == 0)
- continue;
-
- // A heightField might not have any output connections, so
- // look for an input connection before treating it as
- // just a regular utility node...
- //
- if( $type == "heightField" ) {
- $conn = `listConnections -connections true
- -source true -shapes true $node`;
- if( size( $conn ) != 0 ) {
- continue;
- }
- }
-
- tokenize ($class[0], "/", $base);
- if ($base[0] == "texture" ||
- $base[0] == "utility" ||
- $base[0] == "imageplane" ||
- $base[0] == "shader")
- {
- // It's a texture, postprocess or utility node.
- // Now determine if the readable connections are done.
- $shouldDelete = true;
-
- $conn = `listConnections -connections true -source false -shapes true $node`;
- int $connCount = size($conn);
- for ($j = 0; $j < $connCount; $j+=2) {
- $attrName = match (".message",$conn[$j]);
- if ($attrName == ".message") {
- // must explicitly check for the following
- // destinations on a message attribute:
- // shading engine, arrayMapper, or a
- // camera in the case of imagePlane or
- // cameraView
- $connType = `nodeType $conn[$j+1]`;
- if ($connType == "shadingEngine"
- || $connType == "camera"
- || $connType == "imagePlane"
- || $connType == "arrayMapper")
- {
- $shouldDelete = false;
- break;
- }
- }
- else {
- $shouldDelete = false;
- break;
- }
- } // foreach destination connection
- if ($shouldDelete) {
- deleteIfNotReferenced $node;
- $deleteAnything = true;
- }
- } // node is texture, utility, or shader
-
- $shouldDelete = false;
- } // foreach dependency node
- $oldSizeAll = $count;
- }
- else {
- $deleteAnything = false;
- }
- clear $class;
- clear $base;
- }
- }
-